package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.UserService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.vo.request.UpdateUserVo;
import com.rm.zeyou.vo.request.UserBindTelVo;
import com.rm.zeyou.vo.request.UserCodeLoginVo;
import com.rm.zeyou.vo.request.UserWXLoginVo;
import com.rm.zeyou.vo.response.PersonalCenterResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:09
 */
@Api(tags = "用户相关")
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private UserService userService;
    @Resource
    private LoginUtil loginUtil;


    @ApiOperation("验证码登录")
    @PostMapping("userCodeLogin")
    public ApiRestResponse<Map<String,String>> userCodeLogin(@RequestBody UserCodeLoginVo loginVo) {
        return userService.userCodeLogin(loginVo);
    }

    @ApiOperation("微信登录")
    @PostMapping("userWXLogin")
    public ApiRestResponse<Map<String,String>> userWXLogin(@RequestBody UserWXLoginVo loginVo) {
        return userService.userWXLogin(loginVo);
    }


    @ApiOperation("修改用户信息")
    @PostMapping("updateUser")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> updateUser(@RequestBody UpdateUserVo updateVo) {
        User user = loginUtil.getUser();
        return userService.updateUser(user,updateVo);
    }

    @ApiOperation("退出登录")
    @PostMapping("userLoginOut")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Void> userLoginOut() {
        User user = loginUtil.getUser();
        return userService.userLoginOut(user.getId());
    }


    @ApiOperation("个人中心")
    @GetMapping("personalCenter")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<PersonalCenterResponseVo> personalCenter() {
        User user = loginUtil.getUser();
        return userService.personalCenter(user);
    }

    @ApiOperation("用户绑定手机号")
    @PostMapping("userBindTel")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> userBindTel(@RequestBody UserBindTelVo bindTelVo) {
        User user = loginUtil.getUser();
        return userService.userBindTel(user,bindTelVo);
    }

    @ApiOperation("用户绑定微信")
    @PostMapping("userBindWx")
    @SaCheckLogin(type = "user")
    public ApiRestResponse userBindWx(@RequestBody UserBindTelVo bindTelVo) {
        User user = loginUtil.getUser();
        return userService.userBindWx(user,bindTelVo);
    }

    @ApiOperation("APP微信登录")
    @PostMapping("userAPPWXLogin")
    public ApiRestResponse userAPPWXLogin(@RequestBody UserWXLoginVo loginVo) {
        return userService.userAPPWXLogin(loginVo);
    }

    @ApiOperation("用户APP绑定微信")
    @PostMapping("userAPPBindWx")
    @SaCheckLogin(type = "user")
    public ApiRestResponse userAPPBindWx(@RequestBody UserBindTelVo bindTelVo) {
        User user = loginUtil.getUser();
        return userService.userAPPBindWx(user,bindTelVo);
    }
}
